package com.fowo.api.controller.shipment.fbainvoice;

import com.fowo.api.model.fbainvoice.FBAInvoiceReleaseInventoryAction;
import com.fowo.api.model.fbainvoice.FBAInvoiceVo;
import com.fowo.api.service.impl.FBAInvoiceServiceImpl;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Component()
public class fbaInvoiceReleaseInventoryAction implements FBAInvoiceReleaseInventoryAction {
    @Resource
    private FBAInvoiceServiceImpl fbaInvoiceServiceImpl;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void run(List<Long> idList) throws Exception {
        for(int i=0;i<idList.size();i++){
            Long l = idList.get(i);
            suoku(l);
        }
    }

    private void suoku(Long l) throws Exception {
        FBAInvoiceVo voById = fbaInvoiceServiceImpl.getVoById(l);
        if(voById.getIslockinventory().equals("1")){
            fbaInvoiceServiceImpl.cancelLocksInventory(l);
            fbaInvoiceServiceImpl.cancelLockpInventory(l);
            //修改为锁库存状态111
            voById.setIslockinventory("0");
            //改为带分配
            voById.setInvoiceStatus("10");
            fbaInvoiceServiceImpl.update(voById);
        }

    }
}
